package org.sixtynine.stock.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.sixtynine.stock.entity.User;

/**
 * session object
 * 
 * @author Thilanka
 *
 */
public class SessionBean {
	public static final String USER = "LOGIN_USER";

	private HttpSession session;
	private HttpServletRequest request;
	private HttpServletResponse response;

	public static SessionBean getInstance(HttpServletRequest httpServletRequest) {
		return new SessionBean(httpServletRequest.getSession(),
				httpServletRequest);
	}

	private SessionBean(HttpSession session, HttpServletRequest request) {
		super();
		this.session = session;
		this.request = request;
	}

	private SessionBean(HttpSession session, HttpServletRequest request,
			HttpServletResponse response) {
		super();
		this.session = session;
		this.request = request;
		this.response = response;
	}

	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	public Object getAttr(String param) {
		return session.getAttribute(param);
	}

	public void setAttr(String param, Object obj) {
		session.setAttribute(param, obj);
	}

	public User getUser() {
		return (User) getAttr(USER);
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

}
